﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using WaitLess.Business.Data.Foursquare;
using WaitLess.Business.Data.Foursquare.Interfaces;
using WaitLess.Business.Data.Model.Foursquare.VenuesResponse;
using WaitLess.Business.Data.Web;
using WaitLess.Business.Data.Web.Interfaces;
using WaitLess.Business.Repositories;
using WaitLess.Business.Repositories.Interfaces;
using WaitLess.Business.Tests.Common;

namespace WaitLess.Business.Tests.Integration.Repositories.VenuesRepositorySpecifications
{
    [TestClass]
    public class WhenGetByQuery : AsyncTestBase
    {
        protected IVenuesRepository VenuesRepository { get; private set; }
        protected IWebRequestor WebRequestor { get; private set; }
        protected IFoursquareContext FoursquareContext { get; private set; }

        protected string Query { get; set; }
        protected string VenueId { get; set; }

        protected VenuesResponse Result { get; set; }

        protected override void Arrange()
        {
            base.Arrange();
            WebRequestor = new WebRequestor();
            FoursquareContext = new FoursquareContext(WebRequestor);
            VenuesRepository = new VenuesRepository(FoursquareContext);

            Query = "Districtshuis Merksem";
            VenueId = "4caec3a61168a093be0a1d23";
        }

        protected override void Act()
        {
            VenuesRepository.GetByName(Query, result =>
            {
                Result = result;
                IsActCompleted = true;
            });
        }

        [TestMethod]
        public void ThenResultShouldNotBeEmpty()
        {
            Assert.IsNotNull(Result);

            var districtshuisMerksem = (from venue in Result.response.venues
                                       where venue.name.Contains(Query)
                                        select venue).SingleOrDefault();

            Assert.IsNotNull(districtshuisMerksem);
            Assert.AreEqual(Query, districtshuisMerksem.name);
            Assert.AreEqual(VenueId, districtshuisMerksem.id);
        }
    }
}
